error array type 'char 256 ' is not assignable 您所在的位置:网站首页 array type char is not assignable error array type 'char 256 ' is not assignable

error array type 'char 256 ' is not assignable

#error array type 'char 256 ' is not assignable| 来源: 网络整理| 查看: 265

这个错误是因为你尝试将一个256个字符的字符数组作为整体进行赋值。在C/C++中,数组名是数组首元素的地址,也就是指针类型,因此是不可赋值的。

解决办法是,如果需要将一个字符数组的值赋给另一个字符数组,可以使用strcpy()函数或者memcpy()函数来完成。例如:

char source_array[256] = "hello world"; char dest_array[256]; strcpy(dest_array, source_array); // 使用strcpy()函数复制

或者:

char source_array[256] = "hello world"; char dest_array[256]; memcpy(dest_array, source_array, sizeof(source_array)); // 使用memcpy()函数复制

这样就可以避免出现“array type 'char 256' is not assignable”的错误。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有